package com.learnspringboot.hello.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learnspringboot.hello.mapper.UserMapper;
import com.learnspringboot.hello.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Slf4j
public class UserService {
    // userMapper实现自BaseMapper，所有拥有Mybatis的API方法
    @Autowired
    private UserMapper userMapper;

    // 查询所有的user
    public List<User> findAll(){

        // LambdaQueryWrapper为mybatisplus中的类
        return userMapper.selectList(new LambdaQueryWrapper<>());
    }

    //分页查询user
    public List<User> findPage(int page, int size){
        Page<User> upage = new Page<User>(page, size);
        Page<User> userPage = userMapper.selectPage(upage, new LambdaQueryWrapper<>());

        log.info("total", userPage.getTotal());
        log.info("pages", userPage.getPages());
        return userPage.getRecords();
    }

    public List<User> advanceSearch(){
        return userMapper.advanceSearch();
    }
}